package org.mzx.shortLink.adminn.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.mzx.shortLink.adminn.common.ThreadLocal.threadlocal;
import org.mzx.shortLink.adminn.remoteApi.workkApi.feignRecycleBinApi;
import org.mzx.shortLink.starter.convention.Result.Result;
import org.mzx.shortLink.starter.web.Results;
import org.mzx.shortLink.adminn.remoteApi.dto.Request.recycleBinAddDtoReq;
import org.mzx.shortLink.adminn.remoteApi.dto.Response.ShortLinkRecycleBinPageReqDTO;
import org.mzx.shortLink.adminn.remoteApi.dto.Response.TLinkPageDtoResp;
import org.mzx.shortLink.adminn.service.TGroupService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class RecycleBinController {

    private final feignRecycleBinApi recycleBinService;
    private final TGroupService service;

    /**
     * 保存回收站
     */
    @PostMapping("/api/short-link/admin/v1/recycle-bin/save")
    public Result<Void> saveRecycleBin(@RequestBody recycleBinAddDtoReq requestParam) {
        recycleBinService.saveRecycleBin(requestParam);
        return Results.success();
    }

    /**
     * 分页查询回收站短链接
     */
    @GetMapping("/api/short-link/admin/v1/recycle-bin/page")
    public Result<Page<TLinkPageDtoResp>> pageShortLink(ShortLinkRecycleBinPageReqDTO requestParam) {

        requestParam.setGidList(service.selectGidsByUserName(threadlocal.getLoginUser().getUsername()));
        return recycleBinService.pageShortLink(requestParam);
    }

    /**
     * 恢复短链接
     */
    @PostMapping("/api/short-link/admin/v1/recycle-bin/recover")
    public Result<Void> recoverRecycleBin(recycleBinAddDtoReq requestParam) {
        recycleBinService.recoverRecycleBin(requestParam);
        return Results.success();
    }

    /**
     * 移除短链接
     */
    @PostMapping("/api/short-link/admin/v1/recycle-bin/remove")
    public Result<Void> removeRecycleBin(@RequestBody recycleBinAddDtoReq requestParam) {
        recycleBinService.removeRecycleBin(requestParam);
        return Results.success();
    }
}